// packageD/auction/auctioneer-manage/shop_share/shop_share.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths: '',
    uploadUrl: 'upload.uploadPic',
    imageUs: [],
    imgPath: app.globalData.imgPath
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  // 获取删除的下标
  delIntu(e) {
    var delpaths = this.data.imageUs;
    let del = e.currentTarget.id;
    if (del == '0' && delpaths.length == '1') {
      this.setData({
        imageUs: ''
      });
      return;
    }
    var indelpaths = delpaths.splice(del, 1);
    console.log(del);
    console.log(indelpaths);
    this.setData({
      imageUs: indelpaths
    });
  },
  // 上传图片
  tapin() {
    let that = this;
    let ig = '1';
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res.tempFilePaths);
        that.unload({
          tempFilePaths: res.tempFilePaths
        }, ig);
      }
    });
  },
  //多张上传方法 
  unload(data, ig) {
    console.log(ig);
    let urlStr = app.getNetAddresss(this.data.uploadUrl);
    var that = this,
      i = data.i ? data.i : 0,
      success = data.success ? data.success : 0,
      fail = data.fail ? data.fail : 0;
    wx.uploadFile({
      url: urlStr,
      filePath: data.tempFilePaths[i],
      name: 'file',
      formData: null,
      success(resdata) {
        var res = JSON.parse(resdata.data);
        console.log(res);
        console.log(res.data.img);
        that.setData({
          imageUs: that.data.imageUs.concat(res.data.img_url)
        });
      },
      fail(e) {
        fail++;
      },
      complete(e) {
        i++;
        if (i == data.tempFilePaths.length) { //当图片传完时，停止调用     
          console.log('执行完毕');
          console.log('成功：' + success + " 失败：" + fail);
        } else { //若图片还没有传完，则继续调用函数
          data.i = i;
          data.success = success;
          data.fail = fail;
          that.unload(data, ig); //递归，回调自己
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
});